<template>
	<div>
		<h5>编辑话题</h5>
		<group>
			<x-textarea placeholder="标题" :max='30' :rows='1' v-model='topic.title'></x-textarea>
			<x-textarea placeholder="内容" :max='300' :rows='6' v-model='topic.content'></x-textarea>
		</group>
		<x-button type="primary" @click.native='edit'>
			编辑话题
		</x-button>
	</div>
</template>

<script>
	//引入
	import {
		XTextarea,
		Group,
		XInput,
		XButton
	} from 'vux'
	export default { //注册
		components: {
			XTextarea,
			Group,
			XButton
		},
		data: function() {
			return {
				topic: {
					title: '',
					content: ''
				}

			}
		},
		props: ['id'],
		methods: {
			//编辑
			edit:function(){
				this.$router.back();
			},
		},
		//导航守卫
		beforeRouteEnter: function(to, from, next) {
			next(function(vm) {
				vm.$http.get('/topic/' + to.params.id).then(function(res) {
					vm.topic = res.data.data;
				})
			})
		},
		//路由切换
		beforeRouteUpdate: function() {
			var app=this;
			this.$http.get('/topic/'+to.params.id).then(function(res){
				app.Topic=res.data.data;
			})
			next();
		}
	}
</script>

<style>
</style>
